#include <windows.h>
#include "in2.h"
#include "winampin.h"
#include <tchar.h>
#include <dshow.h>
#include "resource.h"
#include <stdio.h>
#include <shellapi.h>
#include "filguid.h"
#include <atlbase.h>


#define CLASSNAME "JillWindow"
#define FULLCLASSNAME "Fullscreen"
#define TEST MessageBox(0,"Test","TestWindow",0)

Audio amod;



In_Module mod = 
{
	IN_VER,
	"Kannan's Movie Player"
#ifdef __alpha
	"(AXP)"
#else
	"(x86)"
#endif
	,
	0,	// hMainWindow
	0,  // hDllInstance
	"avi;dat;mpg;mpeg;mov;ivf;mp4;mpv;mpa;ac3;asf;ivf;m1v;mp2v;mpe;mpv2;wm;wvx;wax;wmp;wmv;qt;vob;divx;asx;ogm;m2v;ogg;mp3;mp2;mp1;wav;au;mid;midi;ac3;rmi;aif;aifc;aiff;snd\0Kannan's"
	,
	1,	// is_seekable
	1, // uses output
	About,
	About,
	Init,
	Quit,
	GetFileInfo,
	infoDlg,
	IsOurFile,
	Play,
	Pause,
	UnPause,
	IsPaused,
	Stop,
	
	GetLength,
	GetOutputTime,
	SetOutputTime,

	SetVolume,
	SetPan,

	0,0,0,0,0,0,0,0,0, // vis stuff


	0,0, // dsp

	0,

	NULL,		// setinfo

	NULL // out_mod

};

#ifdef __cplusplus
extern "C" {
#endif

__declspec( dllexport ) In_Module * winampGetInModule2()
{
	return &mod;
}


#ifdef __cplusplus
}
#endif

SkinMenu exteff[150];

HRESULT RegisterDll(LPSTR szDll, bool bUnregister)
{
	LPSTR szFunction =  bUnregister ? "DllUnregisterServer" : "DllRegisterServer";
	HRESULT hr = S_OK;

	HMODULE hMod = LoadLibrary(szDll);

	if (hMod != NULL)
	{
		typedef HRESULT (_stdcall *DLLPROC)();
		DLLPROC pfnDllProc = reinterpret_cast<DLLPROC>(GetProcAddress(hMod, szFunction));
		
		if (pfnDllProc)
		{
			hr = (*pfnDllProc)();
		}
				
		FreeLibrary(hMod);
	}
	return hr;
}		
void Release()
{
	
	if(gr.pBasicAudio)
		gr.pBasicAudio->Release();
	if(gr.pBasicVideo)
		gr.pBasicVideo->Release();
	if(gr.pMedia)
		gr.pMedia->Release();
	if(gr.pMediaPos)
		gr.pMediaPos->Release();
	if(gr.pVid)
		gr.pVid->Release();
	if(gr.pFilter)
		gr.pFilter->Release();
	if(gr.pEffFilter)
		gr.pEffFilter->Release();
	if(gr.pAudioFilter)
		gr.pAudioFilter->Release();
	if(gr.pAudioInterface)
		gr.pAudioInterface->Release();
	if(gr.pColorSpace)
		gr.pColorSpace->Release();
//	if(gr.pColorSpace1)
	//	gr.pColorSpace1->Release();

	if(gr.pEvent)
	{
		gr.pEvent->SetNotifyWindow(NULL,NULL,NULL);
		gr.pEvent->Release();
	}
	if(gr.pGraph)
		gr.pGraph->Release();
	
	gr.pBasicAudio=NULL;
	gr.pBasicVideo=NULL;
	gr.pGraph=NULL;
	gr.pMedia=NULL;
	gr.pMediaPos=NULL;
	gr.pVid=NULL;
	gr.pFilter=NULL;
	gr.pBasicVideo=NULL;
	gr.pEffFilter=NULL;
	gr.pEvent=NULL;
	gr.pAudioFilter=NULL;
	gr.pAudioInterface=NULL;
	gr.pColorSpace=NULL;
//	gr.pColorSpace1=NULL;
	
	
}
BOOL CALLBACK Resumeproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	char str[30];
	LPDRAWITEMSTRUCT lpdraw;
	RECT r;
	switch(msg)
	{
	case WM_DRAWITEM:
		lpdraw=(LPDRAWITEMSTRUCT)lparam;
		
		if(lpdraw->itemState&(ODS_FOCUS|ODS_DEFAULT))
			SetTextColor(lpdraw->hDC,RGB(0,0,255));
	///	else
			//SetTextColor(lpdraw->hDC,RGB(0,0,0));

		GetClientRect(lpdraw->hwndItem,&r);
		GetWindowText(lpdraw->hwndItem,str,30);
		DrawText(lpdraw->hDC,str,-1,&r,DT_VCENTER|DT_CENTER|DT_SINGLELINE);
		if(lpdraw->CtlID!=IDC_KANNAN)
		{
			POINT p[2];
			p[0].x=0;
			p[0].y=0;
			p[1].x=0;
			p[1].y=r.bottom;
			Polyline(lpdraw->hDC,p,2);
		}
		return 1;
	case WM_COMMAND:
		switch(LOWORD(wparam))
		{
		case IDC_KANNAN:
			DestroyWindow(info.About);
			info.About=CreateDialog(mod.hDllInstance,MAKEINTRESOURCE(IDD_KANNAN),hwnd,(DLGPROC)Kannanproc);
			ShowWindow(info.About,SW_SHOW);
			SetFocus(GetDlgItem(hwnd,IDC_KANNAN));
			break;
		case IDC_RESUMEBU:
			DestroyWindow(info.About);
			info.About=CreateDialog(mod.hDllInstance,MAKEINTRESOURCE(IDD_RESUME),hwnd,(DLGPROC)Resumeprintproc);
			ShowWindow(info.About,SW_SHOW);
			SetFocus(GetDlgItem(hwnd,IDC_RESUMEBU));
			break;
		case IDC_SHORTCUT:
			DestroyWindow(info.About);
			info.About=CreateDialog(mod.hDllInstance,MAKEINTRESOURCE(IDD_SHORTCUT),hwnd,(DLGPROC)Keyboardproc);
			ShowWindow(info.About,SW_SHOW);
			SetFocus(GetDlgItem(hwnd,IDC_SHORTCUT));
			break;
		case IDC_HISTORY:
			DestroyWindow(info.About);
			info.About=CreateDialog(mod.hDllInstance,MAKEINTRESOURCE(IDD_HISTORY),hwnd,(DLGPROC)Historyproc);
			ShowWindow(info.About,SW_SHOW);
			SetFocus(GetDlgItem(hwnd,IDC_HISTORY));
			break;
		}
		break;
	case WM_INITDIALOG:
		info.About=CreateDialog(mod.hDllInstance,MAKEINTRESOURCE(IDD_RESUME),hwnd,(DLGPROC)Resumeprintproc);
		ShowWindow(info.About,SW_SHOW);
		SetFocus(GetDlgItem(hwnd,IDC_RESUMEBU));
		break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
		return TRUE;
	}
	return FALSE;
}

void About(HWND hwndparent)
{
	DialogBox(mod.hDllInstance,MAKEINTRESOURCE(IDD_FORMVIEW),hwndparent,(DLGPROC)Resumeproc);
}
void Init()
{
	WNDCLASSEX wsxf;
	WNDCLASSEX wsx;

	ZeroMemory((void*)&wsx,sizeof(WNDCLASSEX));

	wsx.cbSize=sizeof(WNDCLASSEX);
	wsx.lpfnWndProc=Dlgproc;
	wsx.lpszClassName=CLASSNAME;
	wsx.hInstance=mod.hDllInstance;
	wsx.style=CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
	wsx.hbrBackground=CreateSolidBrush(RGB(0,0,0));
	//wsx.hCursor=info.hcur;
		
	if(!RegisterClassEx(&wsx))
	{
		MessageBox(0,"Movie Window Class Registration Error","Error",0);
	}

	ZeroMemory((void*)&wsxf,sizeof(WNDCLASSEX));

	wsxf.cbSize=sizeof(WNDCLASSEX);
	wsxf.lpfnWndProc=Wndproc;
	wsxf.lpszClassName=FULLCLASSNAME;
	wsxf.hInstance=mod.hDllInstance;
	wsxf.style=CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
	wsxf.hbrBackground=CreateSolidBrush(RGB(0,0,0));

	if(!RegisterClassEx(&wsxf))
	{
		MessageBox(0,"Fullscreen Window Class Registration Error","Error",0);

	}

	CoInitialize(NULL);
			
	info.EffectEnable=GetPrivateProfileInt("Kannan","Effect",0,"Plugin.ini");
	info.Dspeffect=GetPrivateProfileInt("Kannan","DspEffect",1,"Plugin.ini");
	info.AspectRatio=GetPrivateProfileInt("Kannan","AspectRatio",1,"Plugin.ini");
	info.Smooth=GetPrivateProfileInt("Kannan","Smooth",0,"Plugin.ini");
	info.AutoSkin=GetPrivateProfileInt("Kannan","AutoSkin",1,"Plugin.ini");
		
	info.NofSkin=0;
	info.FullScreen=FALSE;

	InitSkinDir();
	LoadCustomSkin();
	InitFilterMenu();
		
	info.CapHeight=GetSystemMetrics(SM_CYSMCAPTION)+GetSystemMetrics(SM_CYFRAME);
	info.Xborder=GetSystemMetrics(SM_CXFRAME);
	info.Yborder=GetSystemMetrics(SM_CYFRAME);

		
	info.hmenumain=GetSubMenu(LoadMenu(mod.hDllInstance,MAKEINTRESOURCE(IDR_FILE)),0);
	InsertMenu(info.hmenumain,GetMenuItemCount(info.hmenumain)-1,MF_POPUP|MF_BYPOSITION,(UINT)info.hmenu,"Skin");
	InsertMenu(info.hmenumain,GetMenuItemCount(info.hmenumain)-2,MF_POPUP|MF_BYPOSITION,(UINT)info.hmenueff,"Effect");
	

	if(info.EffectEnable)
		CheckMenuItem(info.hmenumain,ID_FILE_ENABLEEFFECT,MF_BYCOMMAND|MF_CHECKED);
	if(info.Dspeffect)
		CheckMenuItem(info.hmenumain,ID_FILE_ENABLEDSP,MF_BYCOMMAND|MF_CHECKED);
	if(info.AspectRatio)
		CheckMenuItem(info.hmenumain,ID_FILE_ASPECTRATIO,MF_BYCOMMAND|MF_CHECKED);
	if(info.Smooth)
		CheckMenuItem(info.hmenumain,ID_FILE_ENABLESMOOTH,MF_BYCOMMAND|MF_CHECKED);
	if(info.AutoSkin)
		CheckMenuItem(info.hmenumain,ID_FILE_ENABLEAUTOSKIN,MF_BYCOMMAND|MF_CHECKED);
	if(GetPrivateProfileInt("Kannan","ExtEff",0,"Plugin.ini"))
		CheckMenuItem(info.hmenumain,ID_FILE_ENABLEEXTEFF,MF_BYCOMMAND|MF_CHECKED);
	if(GetPrivateProfileInt("Kannan","EnableampOut",0,"Plugin.ini"))
	{
		CheckMenuItem(info.hmenumain,ID_FILE_ENABLEAMPOUT,MF_BYCOMMAND|MF_CHECKED);
		amod.Enable=1;
	}
	CheckMenuItem(info.hmenueff,GetPrivateProfileInt("Kannan","Effectno",0,"Plugin.ini")+ID_EFFECT,MF_BYCOMMAND|MF_CHECKED);
	
	{
		int i;
		char str[MAX_PATH];
		int f=1;
		ZeroMemory(str,MAX_PATH);
		GetPrivateProfileString("Kannan","Path",0,str,sizeof(str),"Plugin.ini");
		for(i=0;i<info.NofSkin;i++)
			if(!strcmp(skm[i].Path,str))
			{
				f=0;
				CheckMenuItem(info.hmenu,skm[i].Menuid,MF_BYCOMMAND|MF_CHECKED);
			}
		if(f)
			CheckMenuItem(info.hmenu,0,MF_BYPOSITION|MF_CHECKED);	
	}
	{
		int i;
		char str[MAX_PATH];
		int f=1;
		ZeroMemory(str,MAX_PATH);
		GetPrivateProfileString("Kannan","ExtEffStr",0,str,sizeof(str),"Plugin.ini");
		for(i=0;i<info.Exteff;i++)
			if(!strcmp(exteff[i].Path,str))
			{
				f=0;
				CheckMenuItem(info.hmenuexteff,exteff[i].Menuid,MF_BYCOMMAND|MF_CHECKED);
			}
		if(f)
			CheckMenuItem(info.hmenuexteff,0,MF_BYPOSITION|MF_CHECKED);	
	}
	
	gr.pBasicAudio=NULL;
	gr.pBasicVideo=NULL;
	gr.pGraph=NULL;
	gr.pMedia=NULL;
	gr.pMediaPos=NULL;
	gr.pVid=NULL;
	gr.pFilter=NULL;
	gr.pEffFilter=NULL;
	gr.pEvent=NULL;
	gr.pAudioFilter=NULL;
	gr.pAudioInterface=NULL;
	gr.pColorSpace=NULL;
}
void Quit()
{
	
	DestroyMenu(info.hmenu);
	DestroyMenu(info.hmenueff);
	DestroyMenu(info.hmenumain);
	DestroyWindow(info.hwnd);
	DestroyCursor(info.hcur);
	UnregisterClass(CLASSNAME,mod.hDllInstance);
	UnregisterClass(FULLCLASSNAME,mod.hDllInstance);	
	int i;
	for(i=0;i<8;i++)
	{
		DeleteObject(sk[i].hbit);
		DeleteDC(sk[i].mhdc);
	
	}
	CoUninitialize();

}
int IsOurFile(char *filename)
{
	HRESULT hr;
	IGraphBuilder *pGraph;
	WCHAR wfilename[MAX_PATH];
	char t[4];
	
	ZeroMemory(t,4);

	strcpy_s(t,strrchr(filename,'.')+1);
	
	if(!strcmp(strlwr(t),"mp3"))
		return 0;
	else if(!strcmp(strlwr(t),"wav"))
		return 0;
	else if(!strcmp(strlwr(t),"mp2"))
		return 0;
	else if(!strcmp(strlwr(t),"mp1"))
		return 0;
	else if(!strcmp(strlwr(t),"mid"))
		return 0;
		
	CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,IID_IGraphBuilder,(void**)&pGraph);
	mbstowcs(wfilename,filename,sizeof(wfilename));
	hr=pGraph->RenderFile(wfilename,0);
	if(SUCCEEDED(hr))
	{
		pGraph->Release();
		pGraph=NULL;
		return -1;
	
	}
	pGraph->Release();
	pGraph=NULL;
	return 0;
}
int Play(char *filename)
{
	long lVisible;
	HRESULT hr;
	WCHAR wfilename[MAX_PATH];
	RECT r,r1;
	POINT moviesize;
		
	SetFileName(filename);

	InitPlay();
	
	mbstowcs(wfilename,filename,sizeof(wfilename));
	hr=gr.pGraph->RenderFile(wfilename, NULL);
	if(SUCCEEDED(hr))
	{
		gr.pGraph->QueryInterface(CLSID_Filter,(void**)&gr.pFilter);
		gr.pGraph->QueryInterface(IID_IMediaControl, (void **)&gr.pMedia);
		gr.pGraph->QueryInterface(IID_IVideoWindow, (void **)&gr.pVid);
		gr.pGraph->QueryInterface(IID_IMediaPosition, (void **)&gr.pMediaPos);
		gr.pGraph->QueryInterface(IID_IBasicAudio,(void**)&gr.pBasicAudio);
		gr.pGraph->QueryInterface(IID_IBasicVideo,(void**)&gr.pBasicVideo);
		gr.pGraph->QueryInterface(IID_IMediaEventEx,(void**)&gr.pEvent);

		//UnregisterClass(CLASSNAME,mod.hDllInstance);

		//Registermainclass();
		
		info.hwnd=CreateWindowEx(WS_EX_TOOLWINDOW,CLASSNAME,"Kannan's",\
		WS_OVERLAPPED|WS_CAPTION|WS_THICKFRAME,0,0,0,0,mod.hMainWindow,0,mod.hDllInstance,0);

		//SetClassLong(info.hwnd,GCL_HCURSOR,(LONG)info.hcur);
		
		if(!info.hwnd)
			MessageBox(0,"Window Creation Error","ERER",0);
			
		if(gr.pEvent)
			gr.pEvent->SetNotifyWindow((OAHWND)info.hwnd,WM_GRAPHNOTIFY,0);
   			
		if(gr.pVid)
		{
			gr.pVid->put_Owner((OAHWND)info.hwnd);
			gr.pVid->put_WindowStyle(WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE);
			gr.pVid->put_MessageDrain((OAHWND)info.hwnd);
			gr.pVid->put_Visible(OATRUE);
			gr.pVid->put_WindowState(SW_SHOW);
			gr.pVid->put_WindowStyleEx(WS_EX_TOPMOST);
			gr.pVid->HideCursor(OATRUE);

			moviesize.x=352;
			moviesize.y=288;
			if(gr.pBasicVideo)
				gr.pBasicVideo->GetVideoSize(&moviesize.x,&moviesize.y);
		
			if(moviesize.x>352)
				moviesize.x=352;
			if(moviesize.y>288)
				moviesize.y=288;
        
			GetWindowRect(mod.hMainWindow,&r);
			r1=r;
	
			if((r.right+moviesize.x)>GetSystemMetrics(SM_CXSCREEN))
				r.right=r.left-moviesize.x;
			if(r.right<0)
			{
				r.right=(GetSystemMetrics(SM_CXSCREEN)/2)-(moviesize.x/2);
				r.top=r.top+(r.bottom-r.top);
			}
	
			if(r.top+moviesize.y>GetSystemMetrics(SM_CYSCREEN))
			{
				r.top=GetSystemMetrics(SM_CYSCREEN)-moviesize.y;
					if((r.top+moviesize.y)>r1.top)
						r.top=r1.top-moviesize.y;
			}
			if(r.top<0)
				r.top=0;
			
			SetWindowPos(info.hwnd,0,r.right,r.top,moviesize.x,moviesize.y,FALSE);
			GetClientRect(info.hwnd,&r);
			gr.pVid->SetWindowPosition(0,0,r.right,r.bottom);
	
		}
			
		if(gr.pMedia)
		{
			SendMessage(mod.hMainWindow,WM_COMMAND,40058,0);
			SendMessage(mod.hMainWindow,WM_COMMAND,40059,0);
			if(SUCCEEDED(gr.pVid->get_Visible(&lVisible)))
				ShowWindow(info.hwnd,SW_SHOW);
			gr.pMedia->Run();
			return 0;
		}
	}
	return -1;
}
void Pause()
{
	if(gr.pMedia)
		gr.pMedia->Pause();
}
void UnPause()
{
	if(gr.pMedia)
	{
		gr.pMedia->Run();
	}
}
int IsPaused()
{
	OAFilterState ofs;

	if(gr.pMedia)
	{
		gr.pMedia->GetState(INFINITE,&ofs);
	if(ofs==State_Paused)
		return 1;
	}
	return 0;
}
void Stop()
{

	if(gr.pMedia)
		gr.pMedia->Stop();
	
	if(gr.pEffFilter)
		gr.pEffFilter->SetStop();
	if(gr.pAudioFilter)
		gr.pAudioInterface->SetStop();

	Release();

	DestroyWindow(info.hwnd);
	DestroyWindow(info.hwndfull);

}
int GetLength()
{

	REFTIME reftim;
	if(gr.pMediaPos)
	{
		gr.pMediaPos->get_Duration(&reftim);
		return (int)(reftim*1000);
	
	}
	return 0;
}
void InitSkinDir()
{
	char str[MAX_PATH],strpath[MAX_PATH];
	WIN32_FIND_DATA fd;
	HANDLE fh;
	int i;
	ZeroMemory(str,MAX_PATH);
	ZeroMemory(strpath,MAX_PATH);
	GetModuleFileName(mod.hDllInstance,str,MAX_PATH);
	strncpy(strpath,str,(strrchr(str,'\\')-str)+1);
	strcpy(info.Path,strpath);
	strcat(strpath,"KannanSkin\\");
	strcat(strpath,"*.bmp");
	info.hmenu=CreateMenu();
	i=0;
	strcpy(skm[i].Path,"Jill.kzh");
	skm[i].Menuid=ID_PLUGIN+i;
	AppendMenu(info.hmenu,MF_STRING,skm[i].Menuid,"Default Skin");
	i++;
	fh=FindFirstFile(strpath,&fd);
	if(fh!=INVALID_HANDLE_VALUE)
	{
		strcpy(skm[i].Path,fd.cFileName);
		ZeroMemory(str,MAX_PATH);
		strncpy(str,skm[i].Path,(strrchr(skm[i].Path,'.')-skm[i].Path));
		skm[i].Menuid=ID_PLUGIN+i;
		AppendMenu(info.hmenu,MF_STRING,skm[i].Menuid,str);
		i++;
		while(FindNextFile(fh,&fd) && i<150)
		{
			strcpy(skm[i].Path,fd.cFileName);
			ZeroMemory(str,MAX_PATH);
			strncpy(str,skm[i].Path,(strrchr(skm[i].Path,'.')-skm[i].Path));
			skm[i].Menuid=ID_PLUGIN+i;
			AppendMenu(info.hmenu,MF_STRING,skm[i].Menuid,str);
			i++;
		}
		info.NofSkin=i;
	}



}
int GetOutputTime()
{
	REFTIME reftim;
	int ms;
	if(gr.pMediaPos)
	{
		gr.pMediaPos->get_CurrentPosition(&reftim);
		ms=(int)(reftim*1000);
				
	}
	return ms;
}
void SetOutputTime(int ms)
{
	if(gr.pMediaPos)
	{
		gr.pMediaPos->put_CurrentPosition((REFTIME)ms/1000);
		//mod.outMod->Flush(mod.outMod->GetOutputTime()-mod.outMod->GetWrittenTime());
	}
}
void SetVolume(int pt)
{
	if(amod.Enable)
		mod.outMod->SetVolume(pt);
	else
	{
		if(gr.pBasicAudio)
		{
			if(pt==0)
				gr.pBasicAudio->put_Volume(-10000);
			else
				gr.pBasicAudio->put_Volume((long)(((pt-255)/255.0)*3000));
		}
	}
}
void SetPan(int pt)
{
	if(amod.Enable)
		mod.outMod->SetPan(pt);
	else
	{
		if(gr.pBasicAudio)
		{
			if(pt==-127)
				gr.pBasicAudio->put_Balance(-10000);
			else if(pt==127)
				gr.pBasicAudio->put_Balance(10000);
			else
				gr.pBasicAudio->put_Balance((long)((pt/127.0)*2000));
				/*char t[20];
				wsprintf(t,"%d",(120/127.0)*2000);
				MessageBox(0,t,"df",0);*/
		}
	}
	
}
int ProcessSkinMenu(DWORD opt)
{
	int i=0,j=0;
	char str[MAX_PATH];
	if(opt>=(IDS_START+ID_EFFECT) && opt<=(IDS_END+ID_EFFECT+1))
	{
		ZeroMemory(str,MAX_PATH);
		if(gr.pEffFilter)
			gr.pEffFilter->SetOptions(opt-ID_EFFECT);
		wsprintf(str,"%d",opt-ID_EFFECT);
		WritePrivateProfileString("Kannan","Effectno",str,"Plugin.ini");
		for(i=(IDS_START+ID_EFFECT);i<=(IDS_END+ID_EFFECT+1);i++)
			CheckMenuItem(info.hmenueff,i,MF_BYCOMMAND|MF_UNCHECKED);
		CheckMenuItem(info.hmenueff,opt,MF_BYCOMMAND|MF_CHECKED);
		return 1;
	}
	for(i=0;i<info.Exteff;i++)
	{
		if(exteff[i].Menuid==opt)
		{
			if(!HIWORD(GetKeyState(VK_SHIFT)))
			{
				strcpy(str,info.Path);
				strcat(str,"ExtEff\\");
				strcat(str,exteff[i].Path);
				WritePrivateProfileString("Kannan","ExtEffStr",exteff[i].Path,"Plugin.ini");
				CheckMenuItem(info.hmenuexteff,exteff[i].Menuid,MF_BYCOMMAND|MF_CHECKED);
				if(gr.pEffFilter)
				{
					gr.pEffFilter->SetExtEff(str);
					gr.pEffFilter->SetExtEff(GetPrivateProfileInt("Kannan","ExtEff",0,"Plugin.ini"));
				}
				for(j=0;j<info.Exteff;j++)
					CheckMenuItem(info.hmenuexteff,j,MF_BYPOSITION|MF_UNCHECKED);
				CheckMenuItem(info.hmenuexteff,exteff[i].Menuid,MF_BYCOMMAND|MF_CHECKED);
				return 1;
			}
			else
			{
				gr.pEffFilter->SetConfigure(info.hwnd);
			}
		}
	}
	for(i=0;i<info.NofSkin;i++)
	{
		if(skm[i].Menuid==opt)
		{
			WritePrivateProfileString("Kannan","Path",skm[i].Path,"Plugin.ini");
			WritePrivateProfileString("Kannan","SkinMode","1","Plugin.ini");
			LoadCustomSkin();
			SendMessage(info.hwnd,WM_NCPAINT,0,0);
			for(j=0;j<info.NofSkin;j++)
				CheckMenuItem(info.hmenu,j,MF_BYPOSITION|MF_UNCHECKED);
			CheckMenuItem(info.hmenu,opt,MF_BYCOMMAND|MF_CHECKED);

			return 1;			
		}
	}
	return 0;	
}
void InitPlay()
{
	CoInitialize(NULL);

	info.FullScreen=FALSE;
	LoadCustomSkin();

    CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,IID_IGraphBuilder,(void**)&gr.pGraph);

	if(info.Dspeffect)
	{
		GetFilterByName(CLSID_LegacyAmFilterCategory,"AuFilter",&gr.pAudioFilter);

		if(!gr.pAudioFilter)
		{
			char str[MAX_PATH],str1[MAX_PATH];
			GetModuleFileName(mod.hDllInstance,str,MAX_PATH);
			GetFullPathName(str,MAX_PATH,str1,0);
			ZeroMemory(str,MAX_PATH);
			strncpy(str,str1,strrchr(str1,'\\')-str1+1);
			strcat(str,"Filter.ax");
			ZeroMemory(str1,MAX_PATH);
			GetSystemDirectory(str1,MAX_PATH);
			strcat(str1,"\\Filter.ax");
			CopyFile(str,str1,FALSE);
			RegisterDll(str1,FALSE);
			DialogBox(mod.hDllInstance,MAKEINTRESOURCE(IDD_FORMVIEW),mod.hMainWindow,(DLGPROC)Resumeproc);
			GetFilterByName(CLSID_LegacyAmFilterCategory,"AuFilter",&gr.pAudioFilter);
		
		}
	
		if(gr.pAudioFilter)
		{
			gr.pAudioFilter->QueryInterface(IID_AuFilter,(void**)&gr.pAudioInterface);
			if(gr.pAudioInterface)
			{
				gr.pAudioInterface->SetDspfunction(&amod);
			}

		}
		
	}

	if(info.EffectEnable)
	{
		GetFilterByName(CLSID_LegacyAmFilterCategory,"Color Space Converter",&gr.pColorSpace);
		//GetFilterByName(CLSID_LegacyAmFilterCategory,"Color Space Converter",&gr.pColorSpace1);
		GetFilterByName(CLSID_LegacyAmFilterCategory,"Filter",&gr.pFilter);
		
		if(!gr.pFilter)
		{
			char str[MAX_PATH],str1[MAX_PATH];
			GetModuleFileName(mod.hDllInstance,str,MAX_PATH);
			GetFullPathName(str,MAX_PATH,str1,0);
			ZeroMemory(str,MAX_PATH);
			strncpy(str,str1,strrchr(str1,'\\')-str1+1);
			strcat(str,"Filter.ax");
			ZeroMemory(str1,MAX_PATH);
			GetSystemDirectory(str1,MAX_PATH);
			strcat(str1,"\\Filter.ax");
			CopyFile(str,str1,FALSE);
			RegisterDll(str1,FALSE);
			DialogBox(mod.hDllInstance,MAKEINTRESOURCE(IDD_FORMVIEW),mod.hMainWindow,(DLGPROC)Resumeproc);
			GetFilterByName(CLSID_LegacyAmFilterCategory,"Color Space Converter",&gr.pColorSpace);
			GetFilterByName(CLSID_LegacyAmFilterCategory,"Filter",&gr.pFilter);
		
		}

		if(gr.pFilter)
		{
			//gr.pGraph->AddFilter(gr.pFilter,L"Filter");
			gr.pFilter->QueryInterface(IID_FilterInterface,(void**)&gr.pEffFilter);
			
		}
		
		if(gr.pEffFilter)
		{
			{
				char t[MAX_PATH],t1[MAX_PATH];
				ZeroMemory(t1,MAX_PATH);
				ZeroMemory(t,MAX_PATH);
				gr.pEffFilter->SetOptions(GetPrivateProfileInt("Kannan","Effectno",0,"Plugin.ini"));
				gr.pEffFilter->SetSmooth(info.Smooth);
				strcpy(t1,info.Path);
				strcat(t1,"ExtEff\\");
				GetPrivateProfileString("Kannan","ExtEffStr",NULL,t,MAX_PATH,"Plugin.ini");
				strcat(t1,t);
				gr.pEffFilter->SetExtEff(t1);
				gr.pEffFilter->SetExtEff(GetPrivateProfileInt("Kannan","ExtEff",0,"Plugin.ini"));
							
			}
			
		}

	}
	SendMessage(info.hwndfull,WM_CLOSE,0,0);

		
}
/*LRESULT CALLBACK Wndproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
//	HRGN hrgn;
//	RECT r;

	switch(msg)
	{
	case WM_CREATE:
		GetWindowRect(hwnd,&r);
		hrgn=CreateRectRgn(r.left,r.top,r.right,r.bottom);
		SetWindowRgn(hwnd,hrgn,FALSE);
		break;
	case WM_CLOSE:
		//ShowWindow(hwnd,SW_HIDE);
		return 0;
	}
	return DefWindowProc(hwnd,msg,wparam,lparam);
}*/
BOOL CALLBACK Resumeprintproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	RECT r;
	POINT x;
	switch(msg)
	{
	case WM_INITDIALOG:
		
		GetWindowRect(GetDlgItem(GetParent(hwnd),IDC_STATIC1),&r);
		x.x=r.left;
		x.y=r.top;
		ScreenToClient(GetParent(hwnd),&x);
		SetWindowPos(hwnd,0,x.x,x.y,r.right-r.left,r.bottom-r.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		SetWindowPos(GetDlgItem(hwnd,IDC_EDIT1),0,0,0,r.right-r.left,r.bottom-r.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		
		SendDlgItemMessage(hwnd,IDC_EDIT1,WM_SETTEXT,0,(LPARAM)(char*)LockResource(LoadResource(mod.hDllInstance,FindResource(mod.hDllInstance,MAKEINTRESOURCE(IDR_TEXT),"TEXT"))));
		break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
		return TRUE;
	}
	return FALSE;
}
BOOL CALLBACK Keyboardproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	RECT r;
	POINT x;
	switch(msg)
	{
	case WM_INITDIALOG:
		GetWindowRect(GetDlgItem(GetParent(hwnd),IDC_STATIC1),&r);
		x.x=r.left;
		x.y=r.top;
		ScreenToClient(GetParent(hwnd),&x);
		SetWindowPos(hwnd,0,x.x,x.y,r.right-r.left,r.bottom-r.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		SetWindowPos(GetDlgItem(hwnd,IDC_EDIT1),0,0,0,r.right-r.left,r.bottom-r.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		SendDlgItemMessage(hwnd,IDC_EDIT1,WM_SETTEXT,0,(LPARAM)(char*)LockResource(LoadResource(mod.hDllInstance,FindResource(mod.hDllInstance,MAKEINTRESOURCE(IDR_SHORTCUT),"TEXT"))));
		break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
		return TRUE;
	}
	return FALSE;
}
BOOL CALLBACK Historyproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	POINT x;
	RECT r;
	switch(msg)
	{
	case WM_INITDIALOG:
		GetWindowRect(GetDlgItem(GetParent(hwnd),IDC_STATIC1),&r);
		x.x=r.left;
		x.y=r.top;
		ScreenToClient(GetParent(hwnd),&x);
		SetWindowPos(hwnd,0,x.x,x.y,r.right-r.left,r.bottom-r.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		SetWindowPos(GetDlgItem(hwnd,IDC_EDIT1),0,0,0,r.right-r.left,r.bottom-r.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		SendDlgItemMessage(hwnd,IDC_EDIT1,WM_SETTEXT,0,(LPARAM)(char*)LockResource(LoadResource(mod.hDllInstance,FindResource(mod.hDllInstance,MAKEINTRESOURCE(IDR_HISTORY),"TEXT"))));
		break;
	case WM_CLOSE:
		EndDialog(hwnd,0);
		return TRUE;
	}
	return FALSE;
}
BOOL CALLBACK Kannanproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	POINT x;
	RECT r;
	HDC hdc;
	char *txt[]={
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		"=> This is Resumeware <= ",
		" ",
		" ",
		"I sincerely thanks to my R.Venkattathal",
		"and",
		"Sivakami.R,",
		"Harihara Ratha krishnan.K",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		"Developed By",
		" ",
		" ",
		"K.Mohan Ratha Kannan B.E,",
		"Palapalayam,",
		"Pichandampalayam(PO),",
		"Perundurai(TK),",
		"Erode,",
		"TamilNadu,",
		"India-638052.",
		" ",
		" ",
		"Email-Id:kannan_softdev@yahoo.com",
		" ",
		" ",
		"Phone No:91-4294-222991",
		" ",
		" ",
		"Thanks",
		"My neglected beta testers",
		" ",
		" ",
		"Mr.Muthu A kumaran B.E,",
		"email:muthu@thexv.com",
		"email:muthudrizzles@yahoo.com",
		"www.thexv.com",
		"Tirupur.",
		" ",
		" ",
		"Mr.Sai magesh B.E,",
		"email:mageshsai@yahoo.com",
		"Chennai.",
		" ",
		" ",
		"Mr.C Rajesh Kumar B.E,",
		"email:c_rajk@yahoo.com",
		"Erode.",
		" ",
		" ",
		"Mr.S.Sivaprakash B.E",
		"email:shivawaves@msn.com",
		"www.thexv.com/shivawaves",
		"Tirupur.",
		" ",
		" ",
		" ",
		" ",
		" ",
		">>>> Thanks to all who helped this success? <<<<",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		"Copyright K.Kannan",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" ",
		" "//70
	};
	int i,dIndex;
	TEXTMETRIC txtm;
	switch(msg)
	{
	case WM_INITDIALOG:
		GetWindowRect(GetDlgItem(GetParent(hwnd),IDC_STATIC1),&r);
		x.x=r.left;
		x.y=r.top;
		ScreenToClient(GetParent(hwnd),&x);
		SetWindowPos(hwnd,0,x.x,x.y,r.right-r.left,r.bottom-r.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		SetWindowPos(GetDlgItem(hwnd,IDC_STATIC1),0,0,0,r.right-r.left,((r.bottom-r.top)/4)*3,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		SetWindowPos(GetDlgItem(hwnd,IDC_STATIC2),0,0,((r.bottom-r.top)/4)*3+10,r.right-r.left,((r.bottom-r.top)/4)-10,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
		SetTimer(hwnd,ID_TIME,50,0);
		info.uIntex=0;
		info.Index=0;
		return FALSE;
	case WM_TIMER:
		if(LOWORD(wparam)==ID_TIME)
		{
			
			GetClientRect(GetDlgItem(hwnd,IDC_STATIC1),&r);
			hdc=GetWindowDC(GetDlgItem(hwnd,IDC_STATIC1));
			FillRect(hdc,&r,CreateSolidBrush(RGB(0,0,0)));
			GetTextMetrics(hdc,&txtm);
			dIndex=(r.bottom/txtm.tmHeight)+1;
			
			r.top-=info.Index;
			r.bottom=r.top+txtm.tmHeight;
			
		
            if(r.bottom<1)
			{
				info.uIntex++;
				if(info.uIntex>94-dIndex)
					info.uIntex=0;
				info.Index=0;
				GetClientRect(GetDlgItem(hwnd,IDC_STATIC1),&r);
				r.top-=info.Index;
				r.bottom=r.top+txtm.tmHeight;
			
			}
			info.Index++;
			
			SetTextColor(hdc,RGB(255,255,255));
			SetBkMode(hdc,TRANSPARENT);
			for(i=info.uIntex;i<dIndex+info.uIntex;i++)
			{
				DrawText(hdc,txt[i],-1,&r,DT_CENTER);
				r.top=r.bottom;
				r.bottom+=txtm.tmHeight;
				//TextOut(hdc,0,0,txt[0],strlen(txt[0]));
			}
			ReleaseDC(GetDlgItem(hwnd,IDC_STATIC1),hdc);
		}
		break;
	case WM_LBUTTONUP:
		KillTimer(hwnd,ID_TIME);
		SetTimer(hwnd,ID_TIME,50,0);
		break;
	case WM_LBUTTONDOWN:
		KillTimer(hwnd,ID_TIME);
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam))
		{
		case IDC_STATIC2:
			SendMessage(mod.hMainWindow,WM_USER,0,241);
			SendMessage(mod.hMainWindow,WM_USER,(WPARAM)"www.thex.com",241);
			ShellExecute(hwnd,"Open","iexplore.exe","www.thex.com",NULL,SW_SHOWNORMAL);
			break;
		}
		break;
	case WM_CLOSE:
		KillTimer(hwnd,ID_TIME);
		EndDialog(hwnd,0);
		return TRUE;
	}
	return FALSE;
}
LRESULT CALLBACK Dlgproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	POINT pt;
	RECT r;
	double dr;

	switch(msg)
	{
	case WM_CREATE:
		DragAcceptFiles(hwnd,TRUE);
		break;
	case WM_DROPFILES:
		SendMessage(mod.hMainWindow,WM_DROPFILES,wparam,lparam);
		DragFinish((HDROP)wparam);
		return 0;
	case WM_GETMINMAXINFO:
            {
                LPMINMAXINFO lpmm = (LPMINMAXINFO) lparam;
                lpmm->ptMinTrackSize.x = 77;
                lpmm->ptMinTrackSize.y = 77;
			}
            return 0;
	case WM_SETTINGCHANGE:
		info.CapHeight=GetSystemMetrics(SM_CYSMCAPTION)+GetSystemMetrics(SM_CYFRAME);
		info.Xborder=GetSystemMetrics(SM_CXFRAME);
		info.Yborder=GetSystemMetrics(SM_CYFRAME);
		break;
	case WM_ACTIVATE:
	case WM_SETFOCUS:
	case WM_KILLFOCUS:
	case WM_ERASEBKGND:
	case WM_NCPAINT:
		Paint(hwnd);
		return 1;
	case WM_MOUSEMOVE:
		SetCursor(info.hcur);
		return 0;
	case WM_SETCURSOR:
		SetCursor(info.hcur);
		return TRUE;
	case WM_MOVE:
	case WM_SIZE:
		if(gr.pVid)
		{
				GetClientRect(info.hwnd,&r);
				gr.pVid->SetWindowPosition(r.left,r.top,r.right,r.bottom);
		}
		return 0;
	case WM_LBUTTONDOWN:
		info.flag=TRUE;
		GetCursorPos(&info.c1);
		if(gr.pVid)
		{
			if(!info.FullScreen&&info.EffectEnable)
				SetFocus(hwnd);
		}
		break;
	case WM_LBUTTONUP:
		if(info.flag==TRUE)
		{
			info.flag=FALSE;
			GetCursorPos(&pt);
			if(((pt.y-info.c1.y)<50)&&((pt.y-info.c1.y)>-50))
			{
				if((pt.x-info.c1.x)>50)
				{
					SendMessage(mod.hMainWindow,WM_COMMAND,40148,0);
					if((pt.x-info.c1.x)>250)
						SendMessage(mod.hMainWindow,WM_COMMAND,40148,0);

				}
				else if((pt.x-info.c1.x)<-50)
				{
					SendMessage(mod.hMainWindow,WM_COMMAND,40144,0);
					if((pt.x-info.c1.x)<-250)
						SendMessage(mod.hMainWindow,WM_COMMAND,40144,0);

				}
			}
			if(((pt.x-info.c1.x)<50)&&((pt.x-info.c1.x)>-50))
			{
				if((pt.y-info.c1.y)>50)
					SendMessage(mod.hMainWindow,WM_COMMAND,40048,0);
				else if((pt.y-info.c1.y)<-50)
					SendMessage(mod.hMainWindow,WM_COMMAND,40044,0);
			}
			
		}
		break;
	case WM_MOUSEWHEEL:
		if(((short)HIWORD(wparam))>0)
			SendMessage(mod.hMainWindow,WM_COMMAND,40148,0);
		else
			SendMessage(mod.hMainWindow,WM_COMMAND,40144,0);
		break;
	case WM_RBUTTONDOWN:
		SetCursor(info.hcur);
		GetCursorPos(&pt);
		TrackPopupMenu(info.hmenumain,TPM_LEFTALIGN,pt.x,pt.y,0,hwnd,0);
		break;
	case WM_LBUTTONDBLCLK:
		ToggleFullScreen();
		break;
	case WM_MBUTTONDOWN:
		SendMessage(mod.hMainWindow,WM_COMMAND,40046,0);
		break;
	case WM_COMMAND:
		switch(LOWORD(wparam))
		{
		case ID_FILE_PLAY:
			SendMessage(mod.hMainWindow,WM_COMMAND,40045,0);
			break;
		case ID_FILE_PAUSE:
			SendMessage(mod.hMainWindow,WM_COMMAND,40046,0);
			break;
		case ID_FILE_PREVTRACK:
			SendMessage(mod.hMainWindow,WM_COMMAND,40044,0);
			break;
		case ID_FILE_NEXTTRACK:
			SendMessage(mod.hMainWindow,WM_COMMAND,40048,0);
			break;
		case ID_FILE_FULLSCREEN:
			ToggleFullScreen();
			break;
		case ID_FILE_ABOUT:
			About(hwnd);
			break;
		case ID_FILE_ENABLEEXTEFF:
			if(GetPrivateProfileInt("Kannan","ExtEff",0,"Plugin.ini"))
			{
				WritePrivateProfileString("Kannan","ExtEff","0","Plugin.ini");
				if(gr.pEffFilter)
					gr.pEffFilter->SetExtEff(0);
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEEXTEFF,MF_BYCOMMAND|MF_UNCHECKED);
			}
			else
			{
				WritePrivateProfileString("Kannan","ExtEff","1","Plugin.ini");
				if(gr.pEffFilter)
					gr.pEffFilter->SetExtEff(1);
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEEXTEFF,MF_BYCOMMAND|MF_CHECKED);
			}
			break;
		case ID_FILE_ENABLEAMPOUT:
			if(GetPrivateProfileInt("Kannan","EnableampOut",0,"Plugin.ini"))
			{
				WritePrivateProfileString("Kannan","EnableampOut","0","Plugin.ini");
				amod.Enable=0;
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEAMPOUT,MF_BYCOMMAND|MF_UNCHECKED);
			}
			else
			{
				WritePrivateProfileString("Kannan","EnableampOut","1","Plugin.ini");
				amod.Enable=1;
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEAMPOUT,MF_BYCOMMAND|MF_CHECKED);
			}
			break;
		case ID_FILE_ENABLEDSP:
			if(info.Dspeffect)
			{
				info.Dspeffect=FALSE;
				WritePrivateProfileString("Kannan","DspEffect","0","Plugin.ini");
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEDSP,MF_BYCOMMAND|MF_UNCHECKED);
				
			}
			else
			{
				info.Dspeffect=1;
				WritePrivateProfileString("Kannan","DspEffect","1","Plugin.ini");
				if(!gr.pAudioFilter)
				{
					SendMessage(mod.hMainWindow,WM_COMMAND,40047,0);
					SendMessage(mod.hMainWindow,WM_COMMAND,40045,0);
				}
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEDSP,MF_BYCOMMAND|MF_CHECKED);

			}
			break;
		case ID_FILE_ENABLEAUTOSKIN:
			if(info.AutoSkin)
			{
				info.AutoSkin=FALSE;
				WritePrivateProfileString("Kannan","AutoSkin","0","Plugin.ini");
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEAUTOSKIN,MF_BYCOMMAND|MF_UNCHECKED);
				
			}
			else
			{
				info.AutoSkin=1;
				WritePrivateProfileString("Kannan","AutoSkin","1","Plugin.ini");
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEAUTOSKIN,MF_BYCOMMAND|MF_CHECKED);

			}
			break;
		case ID_FILE_ENABLEEFFECT:
			if(info.EffectEnable)
			{
				info.EffectEnable=FALSE;
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEEFFECT,MF_BYCOMMAND|MF_UNCHECKED);
				SendMessage(mod.hMainWindow,WM_COMMAND,40047,0);
				SendMessage(mod.hMainWindow,WM_COMMAND,40045,0);
				WritePrivateProfileString("Kannan","Effect","0","Plugin.ini");
			}
			else
			{
				info.EffectEnable=TRUE;
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLEEFFECT,MF_BYCOMMAND|MF_CHECKED);
				SendMessage(mod.hMainWindow,WM_COMMAND,40047,0);
				SendMessage(mod.hMainWindow,WM_COMMAND,40045,0);
				WritePrivateProfileString("Kannan","Effect","1","Plugin.ini");
			}
			
			break;
		case ID_FILE_ASPECTRATIO:
			if(info.AspectRatio)
			{
				info.AspectRatio=0;
				WritePrivateProfileString("Kannan","AspectRatio","0","Plugin.ini");
				CheckMenuItem(info.hmenumain,ID_FILE_ASPECTRATIO,MF_BYCOMMAND|MF_UNCHECKED);
			}
			else
			{
				info.AspectRatio=1;
				WritePrivateProfileString("Kannan","AspectRatio","1","Plugin.ini");
				CheckMenuItem(info.hmenumain,ID_FILE_ASPECTRATIO,MF_BYCOMMAND|MF_CHECKED);
			}
			break;
		case ID_FILE_ENABLESMOOTH:
			if(info.Smooth)
			{
				info.Smooth=0;
				WritePrivateProfileString("Kannan","Smooth","0","Plugin.ini");
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLESMOOTH,MF_BYCOMMAND|MF_UNCHECKED);
				if(gr.pEffFilter)
					gr.pEffFilter->SetSmooth(info.Smooth);
			}
			else
			{
				info.Smooth=1;
				WritePrivateProfileString("Kannan","Smooth","1","Plugin.ini");
				CheckMenuItem(info.hmenumain,ID_FILE_ENABLESMOOTH,MF_BYCOMMAND|MF_CHECKED);
				if(gr.pEffFilter)
					gr.pEffFilter->SetSmooth(info.Smooth);
			}
			break;
		default:
			ProcessSkinMenu(LOWORD(wparam));			
		}
		break;
	case WM_KEYDOWN:
		switch(LOWORD(wparam))
		{
		case VK_F1:
			About(hwnd);
			break;
		case VK_ADD:
			if(gr.pMediaPos)
			{
				gr.pMediaPos->get_Rate(&dr);
				dr+=0.10;
				gr.pMediaPos->put_Rate(dr);
			}
			break;
		case VK_SUBTRACT:
			if(gr.pMediaPos)
			{
				gr.pMediaPos->get_Rate(&dr);
				dr-=0.10;
				gr.pMediaPos->put_Rate(dr);

			}
			break;
		case 'N':
			if(gr.pMediaPos)
				gr.pMediaPos->put_Rate(1.0);
			break;
		case VK_SPACE:
			SendMessage(mod.hMainWindow,WM_COMMAND,40046,0);
			break;
		case VK_RETURN:
		case 'F':
			ToggleFullScreen();
			break;
		default:
			SendMessage(mod.hMainWindow,msg,wparam,lparam);
			return 0;
		}
		return 0;
	case WM_GRAPHNOTIFY:
		if(gr.pEvent)
		{
			LONG evcode,eparam,eparam1;

			while((gr.pEvent)&&SUCCEEDED(gr.pEvent->GetEvent(&evcode,&eparam,&eparam1,0)))
			{
				if(gr.pEvent)
					gr.pEvent->FreeEventParams(evcode,eparam,eparam1);
				if(EC_COMPLETE==evcode)
				{
					SendMessage(mod.hMainWindow,WM_COMMAND,40048,0);
					return 0;
				}
				
			}
		}
		return 0;
	case WM_CLOSE:
		DragAcceptFiles(hwnd,FALSE);
		Stop();
		DestroyWindow(hwnd);
		return 0;
	}
	return DefWindowProc(hwnd,msg,wparam,lparam);
}
void GetFileInfo(char *file, char *title, int *length_in_ms)
{
	if(!file || !*file)
		file=info.fn;
	else
	{
		SetFileName(file);
		file=info.fn;
	}

	
		if(title)
		{
			wsprintf(title,"%s Kannan's",file);
		}
		if(length_in_ms) *length_in_ms=GetLength();

	
}
int infoDlg(char *fn, HWND hwnd)
{
	long t,t1;
	t=t1=0;
	char str [1024],strt[50];
	wsprintf(str,"Filename            : %s\n",fn);

	if(gr.pBasicVideo)
	{
		gr.pBasicVideo->GetVideoSize(&t,&t1);
		wsprintf(strt,"PictureSize         : %ld x %ld\n",t,t1);
		strcat(str,strt);
	}
	MessageBox(hwnd,str,"Kannan's Movie Info",0);
	return 0;
}
void SetFileName(char* filename)
{
	strcpy(info.fn,(strrchr(filename,'\\')+1));
}
void ToggleFullScreen()
{
	long ax,ay,s;
	RECT r,r1;
	double d;
	HWND hwnd;
	
	if(gr.pVid)
	{
	
		if(info.EffectEnable)
		{
			if(!info.FullScreen)
			{
				gr.pVid->get_MessageDrain(&info.hwnddrain);
				gr.pVid->put_MessageDrain((OAHWND)info.hwnd);
				GetWindowRect(GetDesktopWindow(),&r);
				r1=r;
				info.hwndfull=CreateWindowEx(0,FULLCLASSNAME,"FullScreen",WS_POPUP|WS_VISIBLE,0,0,r.right,r.bottom,0,0,mod.hDllInstance,0);
					//info.hwndfull=FindWindow("Internet Explorer_Server","");
				ShowWindow(info.hwndfull,SW_SHOW);
				gr.pVid->put_Owner((OAHWND)info.hwndfull);
				if(info.AspectRatio)
				{
					if(gr.pBasicVideo)
					{
						gr.pBasicVideo->GetVideoSize(&ax,&ay);
						d=(float)ay/(float)(ax-ay);
						s=(long)((((float)(ax-ay)/(float)ax)*(float)r1.right)*d);
						if(s>r1.bottom)
						{
							d=(float)ax/(float)(ax-ay);
							s=(long)((((float)(ax-ay)/(float)ay)*(float)r1.bottom)*d);
							r.right=s;
						}
						else
							r.bottom=s;
					
						r.top=r.left =0;
						if((r1.bottom-r.bottom)>0)
						{
							s=(long)abs(r.bottom-r1.bottom);
							r.bottom=(long)(r1.bottom-s/2);
							r.top=(long)(s/2);
						}
						if((r1.right-r.right)>0)
						{
							s=(long)abs(r.right-r1.right);
							r.left=(long)(s/2);
							r.right=(long)(r1.right-s/2);
						}

					}
				}
				gr.pVid->put_WindowStyleEx(WS_EX_TOPMOST);
				gr.pVid->get_Owner((OAHWND*)&hwnd);
				gr.pVid->SetWindowPosition(r.left,r.top,r.right-r.left,r.bottom-r.top);
				GetWindowRect(GetDesktopWindow(),&r);
				SetWindowPos(hwnd,HWND_TOPMOST,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
				SetFocus(hwnd);
				info.FullScreen=TRUE;
				
			}
			else
			{
				gr.pVid->put_MessageDrain(info.hwnddrain);
				info.FullScreen=FALSE;
				ShowWindow(info.hwndfull,SW_HIDE);
				gr.pVid->put_Owner((OAHWND)info.hwnd);
				
				DestroyWindow(info.hwndfull);
				
				GetClientRect(info.hwnd,&r);
				SendMessage(info.hwnd,WM_SIZE,0,0);
				UpdateWindow(info.hwnd);
				SetFocus(info.hwnd);
			}
		}
		else
		{
			gr.pVid->get_FullScreenMode(&s);
			if(s==OAFALSE)
			{
				gr.pVid->get_MessageDrain(&info.hwnddrain);
				gr.pVid->put_MessageDrain((OAHWND)info.hwnd);
			//	gr.pVid->HideCursor(OAFALSE);
				gr.pVid->put_FullScreenMode(OATRUE);
				
			}
			else
			{
				gr.pVid->put_MessageDrain(info.hwnddrain);
				gr.pVid->put_FullScreenMode(OAFALSE);
				UpdateWindow(info.hwnd);
				SetFocus(info.hwnd);
					
			}

		}
	}

}
int LoadCustomSkin()
{
	char path[MAX_PATH],str[MAX_PATH];

	if(info.AutoSkin)
	{
		ZeroMemory(str,MAX_PATH);
		SendMessage(mod.hMainWindow,WM_USER,(WPARAM)str,201);
		strcat(str,"\\Normal.cur");
		DestroyCursor(info.hcur);
		info.hcur=NULL;
		info.hcur=(HCURSOR)LoadCursorFromFile(str);
		if(!info.hcur)
			info.hcur=LoadCursor(mod.hDllInstance,MAKEINTRESOURCE(IDC_ARROW1));
	}
	else
		info.hcur=LoadCursor(0,IDC_ARROW);

	ZeroMemory(path,MAX_PATH);
	ZeroMemory(str,MAX_PATH);
	info.SkinMode=GetPrivateProfileInt("Kannan","SkinMode",0,"Plugin.ini");
	//WritePrivateProfileString("Kannan","Jill","Love","Plugin.ini");
	if(info.AutoSkin)
	{
		DeleteObject(sk[0].hbit);
		sk[0].hbit=NULL;
		DeleteDC(sk[0].mhdc);
		sk[0].mhdc=NULL;
		SendMessage(mod.hMainWindow,WM_USER,(WPARAM)str,201);
		strcat(str,"\\avs.bmp");
		sk[0].hbit=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
		if(!sk[0].hbit)
		{
			DeleteObject(sk[0].hbit);
		}
		else
		{
		GetObject(sk[0].hbit,sizeof(BITMAP),&sk[0].bmp);
		sk[0].mhdc=CreateCompatibleDC(NULL);
		SelectObject(sk[0].mhdc,sk[0].hbit);
		return 0;
		}
		
	}
	
	if(info.SkinMode)
	{
		GetPrivateProfileString("Kannan","Path",0,path,sizeof(path),"Plugin.ini");
		strcpy(str,info.Path);
		strcat(str,"KannanSkin\\");
		strcat(str,path);
		/*SendMessage(mod.hMainWindow,WM_USER,(WPARAM)str,201);
		strcat(str,"\\avs.bmp");*/
		sk[0].hbit=(HBITMAP)LoadImage(NULL,str,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE);
		if(!sk[0].hbit)
		{
			DeleteObject(sk[0].hbit);
			info.SkinMode=0;
		}
		else
		{
		GetObject(sk[0].hbit,sizeof(BITMAP),&sk[0].bmp);
		sk[0].mhdc=CreateCompatibleDC(NULL);
		SelectObject(sk[0].mhdc,sk[0].hbit);
		}

	}
	if(!info.SkinMode)
	{
		int i,j=0;
		for(i=IDB_MAIN,j=0;i<=IDB_RIGHTBAR;j++,i++)
		{
			sk[j].hbit=LoadBitmap(mod.hDllInstance,MAKEINTRESOURCE(i));
			GetObject(sk[j].hbit,sizeof(BITMAP),&sk[j].bmp);
			sk[j].mhdc=CreateCompatibleDC(NULL);
			SelectObject(sk[j].mhdc,sk[j].hbit);
		}
	}
	return 0;
}

int GetFilterByName(REFCLSID clsid, char *FilterName, IBaseFilter **pIBasefilter)
{
	char t[MAX_PATH];

	ICreateDevEnum *pICreateDevEnum=NULL;
	
	CoCreateInstance(CLSID_SystemDeviceEnum,NULL,CLSCTX_INPROC,IID_ICreateDevEnum,(void**)&pICreateDevEnum);

	ULONG cFetched;

	IEnumMoniker *pIEnumMoniker=NULL;
	IMoniker *pIMoniker=NULL;

	if(pICreateDevEnum!=NULL)
		pICreateDevEnum->CreateClassEnumerator(clsid,&pIEnumMoniker,0);
	
	if(pIEnumMoniker!=NULL)
	{
		while(pIEnumMoniker->Next(1,&pIMoniker,&cFetched)==S_OK)
		{
			IPropertyBag * pIPropertyBag=NULL;
			
			pIMoniker->BindToStorage(0,0,IID_IPropertyBag,(void**)&pIPropertyBag);
		
			VARIANT Varname;
			VariantInit(&Varname);
			
			if(pIPropertyBag!=NULL)
			{
				
				if(SUCCEEDED(pIPropertyBag->Read(L"FriendlyName",&Varname,0)))
				{
					wcstombs(t,Varname.bstrVal,MAX_PATH);
					
					if(!strcmp(FilterName,t))
					{
							gr.pGraph->RemoveFilter(*pIBasefilter);
							pIMoniker->BindToObject(0,0,IID_IBaseFilter,(void**)pIBasefilter);
							gr.pGraph->AddFilter(*pIBasefilter,Varname.bstrVal);
							return TRUE;
					}
					
				}
				
			}
			VariantClear(&Varname);

			if(pIPropertyBag)
				pIPropertyBag->Release();
			pIPropertyBag=NULL;
			if(pIMoniker)
				pIMoniker->Release();
			pIMoniker=NULL;
		}
		if(pIEnumMoniker)
			pIEnumMoniker->Release();
		pIEnumMoniker=NULL;
		
	}
	if(pICreateDevEnum)
		pICreateDevEnum->Release();
	pICreateDevEnum=NULL;

*pIBasefilter=NULL;
return FALSE;
}
void InitFilterMenu()
{
	int i;
	char buff[50];
	info.hmenueff=CreateMenu();
	{
		char str[MAX_PATH],strpath[MAX_PATH];
		WIN32_FIND_DATA fd;
		HANDLE fh;
		int i;
		info.Exteff=0;
		ZeroMemory(str,MAX_PATH);
		ZeroMemory(strpath,MAX_PATH);
		GetModuleFileName(mod.hDllInstance,str,MAX_PATH);
		strncpy(strpath,str,(strrchr(str,'\\')-str)+1);
		strcat(strpath,"ExtEff\\");
		strcat(strpath,"*.dll");
		info.hmenuexteff=CreateMenu();
		i=0;
		fh=FindFirstFile(strpath,&fd);
		if(fh!=INVALID_HANDLE_VALUE)
		{
			strcpy(exteff[i].Path,fd.cFileName);
			ZeroMemory(str,MAX_PATH);
			strncpy(str,exteff[i].Path,(strrchr(exteff[i].Path,'.')-exteff[i].Path));
			exteff[i].Menuid=ID_EXTEFF+i;
			AppendMenu(info.hmenuexteff,MF_STRING,exteff[i].Menuid,str);
			i++;
			while(FindNextFile(fh,&fd) && i<150)
			{
				strcpy(exteff[i].Path,fd.cFileName);
				ZeroMemory(str,MAX_PATH);
				strncpy(str,exteff[i].Path,(strrchr(exteff[i].Path,'.')-exteff[i].Path));
				exteff[i].Menuid=ID_EXTEFF+i;
				AppendMenu(info.hmenuexteff,MF_STRING,exteff[i].Menuid,str);
				i++;
			}
			info.Exteff=i;
		}
		if(!info.Exteff)
			AppendMenu(info.hmenuexteff,MF_STRING,ID_EXTEFF,"None");
		
	}
	AppendMenu(info.hmenueff,MF_POPUP,(UINT)info.hmenuexteff,"ExternalEff");
	//AppendMenu(info.hmenueff,MF_STRING,ID_EFFECT,"Enable Effect");
	for(i=IDS_START;i<=IDS_END;i++)
	{
		ZeroMemory(buff,50);
		LoadString(mod.hDllInstance,i,buff,50);
		AppendMenu(info.hmenueff,MF_STRING,ID_EFFECT+i,buff);
	}
	AppendMenu(info.hmenueff,MF_STRING,ID_EFFECT+IDS_END+1,"No Effect");
	//
	


}
LRESULT CALLBACK Wndproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	HRGN hrgn;
	RECT r;
	
	switch(msg)
	{
	case WM_CREATE:
		
		GetWindowRect(GetDesktopWindow(),&r);
		SetWindowPos(info.hwndfull,HWND_TOPMOST,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
		hrgn=CreateRectRgn(0,0,r.right,r.bottom);
		SetWindowRgn(info.hwndfull,hrgn,FALSE);
		return 0;
	case WM_MOUSEMOVE:
		SetCursor(info.hcur);
		return 1;
	case WM_SETCURSOR:
		SetCursor(info.hcur);
		return TRUE;
	case WM_LBUTTONDBLCLK:
	case WM_LBUTTONUP:
	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_MBUTTONUP:
	case WM_RBUTTONUP:
	case WM_RBUTTONDBLCLK:
	case WM_RBUTTONDOWN:
	case WM_KEYDOWN:
	case WM_COMMAND:
	case WM_MOUSEWHEEL:
		Dlgproc(info.hwnd,msg,wparam,lparam);
		return 0;
	case WM_SETTINGCHANGE:
	case WM_KILLFOCUS:
		if(info.FullScreen)
		{
			ToggleFullScreen();
		}
		break;
	case WM_CLOSE:
		DestroyWindow(hwnd);
		return 0;
	}
	return DefWindowProc(hwnd,msg,wparam,lparam);
}
int Paint(HWND hwnd)
{
	RECT r;
	HDC hdc;
		hdc=GetWindowDC(hwnd);
		GetWindowRect(hwnd,&r);
		if(info.SkinMode)
		{
		StretchBlt(hdc,0,0,49,info.CapHeight,sk[0].mhdc,15,0,49,14,SRCCOPY);
		StretchBlt(hdc,49,0,(r.right-r.left)-64,info.CapHeight,sk[0].mhdc,66,0,13,14,SRCCOPY);
		StretchBlt(hdc,(r.right-r.left)-15,0,15,info.CapHeight,sk[0].mhdc,81,0,15,14,SRCCOPY);
		
		StretchBlt(hdc,0,info.CapHeight,info.Xborder,(r.bottom-r.top)-(info.Yborder+info.CapHeight),sk[0].mhdc,0,16,6,171,SRCCOPY); 
		StretchBlt(hdc,(r.right-r.left)-info.Xborder,info.CapHeight,info.Xborder,(r.bottom-r.top)-(info.Yborder+info.CapHeight),sk[0].mhdc,8,16,5,171,SRCCOPY); 
		
		StretchBlt(hdc,0,(r.bottom-r.top)-info.Yborder,49,info.Yborder,sk[0].mhdc,15,16,49,5,SRCCOPY);
		StretchBlt(hdc,49,(r.bottom-r.top)-info.Yborder,(r.right-r.left)-64,info.Yborder,sk[0].mhdc,66,16,13,5,SRCCOPY);
		StretchBlt(hdc,(r.right-r.left)-16,(r.bottom-r.top)-info.Yborder,16,info.Yborder,sk[0].mhdc,81,16,15,5,SRCCOPY);
		}
		else
		{
		StretchBlt(hdc,0,0,sk[0].bmp.bmWidth,info.CapHeight,sk[0].mhdc,0,0,sk[0].bmp.bmWidth,15,SRCCOPY);
		StretchBlt(hdc,sk[0].bmp.bmWidth,0,(r.right-r.left)-66,info.CapHeight,sk[1].mhdc,0,0,sk[1].bmp.bmWidth,15,SRCCOPY);
		StretchBlt(hdc,(r.right-r.left)-16,0,16,info.CapHeight,sk[2].mhdc,0,0,sk[2].bmp.bmWidth,15,SRCCOPY);
		
		StretchBlt(hdc,0,info.CapHeight,info.Xborder,(r.bottom-r.top)-(info.Yborder+info.CapHeight),sk[6].mhdc,0,0,5,15,SRCCOPY); 
		StretchBlt(hdc,(r.right-r.left)-info.Xborder,info.CapHeight,info.Xborder,(r.bottom-r.top)-(info.Yborder+info.CapHeight),sk[7].mhdc,0,0,4,14,SRCCOPY); 
		
		StretchBlt(hdc,0,(r.bottom-r.top)-info.Yborder,50,info.Yborder,sk[3].mhdc,0,0,50,5,SRCCOPY);
		StretchBlt(hdc,50,(r.bottom-r.top)-info.Yborder,(r.right-r.left)-66,info.Yborder,sk[4].mhdc,0,0,14,5,SRCCOPY);
		StretchBlt(hdc,(r.right-r.left)-16,(r.bottom-r.top)-info.Yborder,16,info.Yborder,sk[5].mhdc,0,0,16,5,SRCCOPY);
		}
		ReleaseDC(hwnd,hdc);
		return 0;
}
int Registermainclass()
{
	
	return 0;
}
/*void CALLBACK OneShotTimer(UINT wTimerID, UINT msg, 
    DWORD dwUser, DWORD dw1, DWORD dw2) 
{ 
	char t[20];
	ZeroMemory(t,20);
	wsprintf(t,"%d %d %d",mod.outMod->GetOutputTime(),mod.outMod->GetWrittenTime(),abs(mod.outMod->GetWrittenTime()-mod.outMod->GetOutputTime()));
	SetWindowText(mod.hMainWindow,t);
	 if(mod.outMod->GetWrittenTime()==mod.outMod->GetOutputTime())
	 {
		//if(gr.pMedia)
			//gr.pMedia->Run();
		SendMessage(mod.hMainWindow,WM_COMMAND,40046,0);
		timeKillEvent(wTimerID);
		TIMECAPS tc;
		timeGetDevCaps(&tc,sizeof(TIMECAPS));
		timeBeginPeriod(min(max(tc.wPeriodMax,1),tc.wPeriodMin));
		wTimerID=0;
	 }
	 else
		 gr.pMedia->Pause();
    
} 
*/

int Audio::open(int bps,int nch,int srate)
{
	int r=0;
	r=mod.outMod->Open(srate,nch,bps,-1,-1);
	mod.SetInfo((srate*(bps/8)*nch)/1000,srate/1000,nch,1);
	mod.SAVSAInit(0,srate);
	mod.VSASetInfo(nch,srate);
	
	return r;
}
int Audio::write(BYTE* samples,int numsamples,int bps,int nch,int srate)
{
	
	int r=0;
	int t=0;//mod.GetOutputTime();
	
	int numSample=(numsamples)/(sizeof(short int)*nch);
				
	if (mod.dsp_isactive()&&info.Dspeffect)
		mod.dsp_dosamples((short int*)samples,numSample,bps,nch,srate);

	mod.SAAddPCMData((char *)samples,nch,bps,t);
	mod.VSAAddPCMData((char *)samples,nch,bps,t);

	if(Enable)
	{
		mod.outMod->Write((char*)samples,numsamples);
		ZeroMemory(samples,numsamples);
	}
				
	return 0; 
}
void Audio::flush()
{
	mod.outMod->Flush(0);
}
void Audio::close()
{
	mod.outMod->Flush(0);
	mod.outMod->Close();
}
Audio::Audio()
{
	Enable=0;
}




